﻿Imports System.Security.Principal

<Serializable()> _
Public Class Usuario
    Inherits BaseDominio
    Implements IIdentity

    Private _login As String
    Public Overridable Property Login() As String
        Get
            Return _login
        End Get
        Set(ByVal value As String)
            _login = value
        End Set
    End Property

    Private _nome As String
    Public Overridable Property Nome() As String
        Get
            Return _nome
        End Get
        Set(ByVal value As String)
            _nome = value
        End Set
    End Property

    Private _email As String
    Public Overridable Property Email() As String
        Get
            Return _email
        End Get
        Set(ByVal value As String)
            _email = value
        End Set
    End Property

    Private _dataCriacao As Nullable(Of DateTime)
    Public Overridable Property DataCriacao() As Nullable(Of DateTime)
        Get
            Return _dataCriacao
        End Get
        Set(ByVal value As Nullable(Of DateTime))
            '_dataCriacao = value
        End Set
    End Property

    Private _bloqueado As Boolean
    Public Overridable Property Bloqueado() As Boolean
        Get
            Return _bloqueado
        End Get
        Set(ByVal value As Boolean)
            '_bloqueado = value
        End Set
    End Property

    Private _ultimoAcesso As Nullable(Of DateTime)
    Public Overridable Property UltimoAcesso() As Nullable(Of DateTime)
        Get
            Return _ultimoAcesso
        End Get
        Set(ByVal value As Nullable(Of DateTime))
            _ultimoAcesso = value
        End Set
    End Property

    Private _tentativasDeLogin As Integer
    Public Overridable Property TentativasDeLogin() As Integer
        Get
            Return _tentativasDeLogin
        End Get
        Set(ByVal value As Integer)
            _tentativasDeLogin = value
        End Set
    End Property

    Private _papeis As IList(Of Papel)
    Public Overridable Property Papeis() As IList(Of Papel)
        Get
            Return _papeis
        End Get
        Set(ByVal value As IList(Of Papel))
            _papeis = value
        End Set
    End Property


#Region "Negocio"

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overridable Function Buscar(ByVal _id As Long) As Usuario
        Return MyBase.UsuarioDao.Buscar(_id)
    End Function

    Public Overridable Sub Salvar()
        MyBase.UsuarioDao.Salvar(Me)
    End Sub

    Public Overridable Sub AdicionarPapel(ByVal _papel As Papel)
        If _papeis Is Nothing Then _papeis = New List(Of Papel)
        _papeis.Add(_papel)
        Me.UsuarioDao.Alterar(Me)
    End Sub

    Public Overridable Sub RemoverPapel(ByVal _papel As Papel)
        Me._papeis.Remove(_papel)
        Me.UsuarioDao.Alterar(Me)
    End Sub

    Public Overridable Sub Bloquear()
        Me._bloqueado = True
        Me.UsuarioDao.Alterar(Me)
    End Sub

    Public Overridable Sub Desbloquear()
        Me._bloqueado = False
        Me.UsuarioDao.Alterar(Me)
    End Sub

    Public Overridable Sub ResetarASenha()
        Throw New NotImplementedException
    End Sub

    Public Overridable Sub AlterarSenha(ByVal _senhaAntiga As String, ByVal _senhaNova As String, ByVal _confirmaSenhaNova As String)
        Throw New NotImplementedException
    End Sub

    Public Overridable Function UsuarioEstaBloqueado() As Boolean
        Throw New NotImplementedException
    End Function

    Public Overridable Function SenhaEstahExpirada() As Boolean
        Throw New NotImplementedException
    End Function

    Public Overridable Sub AlterarDataExpiracaoSenha(ByVal _novaData As Date)
        Throw New NotImplementedException
    End Sub

#End Region

    Public Overridable ReadOnly Property AuthenticationType() As String Implements System.Security.Principal.IIdentity.AuthenticationType
        Get

        End Get
    End Property

    Public Overridable ReadOnly Property IsAuthenticated() As Boolean Implements System.Security.Principal.IIdentity.IsAuthenticated
        Get

        End Get
    End Property

    Public Overridable ReadOnly Property Name() As String Implements System.Security.Principal.IIdentity.Name
        Get

        End Get
    End Property

End Class
